package com.sino.androiddesign.customView


import android.content.Context
import android.graphics.*
import android.os.Bundle
import android.support.v4.app.Fragment
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.sino.androiddesign.R


/**
 * A simple [Fragment] subclass.
 *
 */
class Demo4PathFragment : Fragment() {

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_demo4_path, container, false)
    }


}

class Demo4TestView : View {
    constructor(context: Context) : this(context, null)
    constructor(context: Context, attributeSet: AttributeSet?) : super(context, attributeSet)

    private val mPaint: Paint = Paint()

    init {
        mPaint.color = Color.BLACK
        mPaint.style = Paint.Style.STROKE
        mPaint.strokeWidth = 10f


    }

    private val mPath =Path()

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        canvas!!.translate( resources.displayMetrics.widthPixels/2.toFloat(),resources.displayMetrics.heightPixels/2.toFloat())

        /**
         * moveTo,setLastPoint,lineTo,close
         */

//        mPath.lineTo(200f,200f)
//        mPath.lineTo(200f,0f)
//        canvas.drawPath(mPath,mPaint)

        /**
         * moveTo setLastPoint 的区别在于
         * 前者对之前的操作无影响,
         * 后者有,并且会重置上一次操作的最后一个点
         *
         * close 闭合路径,形成封闭图形
         */
//        mPath.lineTo(200f,200f)
//        mPath.moveTo(200f,100f)
//        mPath.lineTo(200f,0f)
//        canvas.drawPath(mPath,mPaint)

//        mPath.lineTo(200f,200f)
//        mPath.setLastPoint(200f,100f)
//        mPath.lineTo(200f,0f)
//        mPath.close()
//        canvas.drawPath(mPath,mPaint)


        /**
         * addXXX 与arcTo
         */

        //Path.Direction
//        mPath.addRect(-100f,-100f,100f,100f,Path.Direction
// .CW)
//        mPath.setLastPoint(-200f,200f)
//        canvas.drawPath(mPath,mPaint)

//        mPath.addRect(-100f,-100f,100f,100f,Path.Direction.CCW)
//        mPath.setLastPoint(-200f,200f)
//        canvas.drawPath(mPath,mPaint)

        //addPath()
//        canvas.scale(1f,-1f)
//
//        mPath.addRect(-200f,-200f,200f,200f,Path.Direction.CW)
//        val src = Path()
//        src.addCircle(0f,0f,100f,Path.Direction.CW)
//
//        mPath.addPath(src,0f,200f)
//        mPaint.color=Color.BLACK
//        canvas.drawPath(mPath,mPaint)

        //addArc()

//        canvas.scale(1f,-1f)
//        mPath.lineTo(100f,100f)
//        val oval = RectF(0f,0f,200f,200f)
//        mPath.addArc(oval,0f,270f)
//
//        canvas.drawPath(mPath,mPaint)


        //arcTo
        canvas.scale(1f,-1f)
        mPath.lineTo(100f,100f)
        val oval = RectF(0f,0f,200f,200f)
        mPath.arcTo(oval,0f,270f)

        canvas.drawPath(mPath,mPaint)

    }

}
